import { api } from '@/api/request'
import type { PageData, PageQuery } from '@/types'

// 账单信息
export interface AccountInfo {
    id : number | null   // 账单的id
    user_id: number
    family_id: number
    amount: number
    type : string
    remark: string
    recoded_data: Date
  }

// 账单查询参数
export interface AccountQuery extends PageQuery {
    start_datetime : Date
    end_datetime : Date
    type_ : string
    months : number
  }

// 后端返回的分类统计项类型
export interface AccountCategoryStat {
    category: string
    amount: string
    amount_formatted: string
    count: number
    percentage: number
  }


// 后端返回的趋势数据项的类型
export interface TrendDataItem {
    month: string;   // 或 number, 取决于后端返回的具体格式
    income: number;
    expense: number;
    // 可能还有其他字段...
}


// 账单相关 API
export const AccountApi = {
    // 新增账单 
    AccountCreate: (data:AccountInfo) => {
      return api.post('/family/account/create', data);
    },
    
    // 删除账单 
    AccountDelete: (data:AccountInfo) => {
        const { id } = data;  
        return api.delete(`/family/account/account_info/${id}`); 
    },

    // 账单更新 
    AccountUpdate: (data:AccountInfo) => {
      const { id, ...updateData } = data;
      return api.put(`/family/account/account_info/${id}`, updateData);  
    },

    getAccountDetail: (data:AccountInfo) => {
      const { id } = data;
      return api.get(`/family/account/account_info/${id}`);  
    },

    // 获取账单列表
    getAccountList: (params: AccountQuery) => 
        api.get<PageData<AccountInfo>>('/family/account/list', { params }),
    
    // 获取账单统计数据
    getAccountStatistics: (params: AccountQuery) => 
        api.get<PageData<AccountInfo>>('/family/account/statistics', { params }),
    
    // 获取账单分类统计数据
    getAccountCategoryStats: (params: AccountQuery) => 
        api.get<PageData<AccountInfo>>('/family/account/category-stats', { params }),
    
    // 获取账单月度统计数据
    getAccountTrend: (params: AccountQuery) => 
        api.get<PageData<AccountInfo>>('/family/account/trend', { params }),

};